package com.note.chh.notebook.Adapter;

import android.net.Uri;
import android.support.annotation.LayoutRes;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.note.chh.notebook.R;
import com.note.chh.notebook.Uitls.localFile.FileManager;

import java.io.File;

/**
 * Created by caihuahui on 2018/3/1.
 */

public class PMVAdapter extends BaseQuickAdapter<String,BaseViewHolder> {
    public PMVAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        String[] split = item.split("\\|");
        ImageView mImage_pmv = helper.getView(R.id.mImage_pmv);
        if (split[0].equals("add")) {
            mImage_pmv.setImageResource(R.mipmap.addimg);
            helper.setVisible(R.id.mLinear_pmv,false);
        } else if(split[0].equals("p")){
            helper.setVisible(R.id.mLinear_pmv,false);
            Glide.with(mContext).load(split[1]).into(mImage_pmv);
        } else if (split[0].equals("m")) {
            mImage_pmv.setImageResource(R.mipmap.music_icon);
            helper.setVisible(R.id.mLinear_pmv,true);
            helper.setImageResource(R.id.mImage_type,R.mipmap.picture_audio);
            helper.setText(R.id.mText_pmv,toTime(split[2]));
            Glide.with(mContext).load(R.mipmap.audio_icon).into(mImage_pmv);
        } else if (split[0].equals("v")) {
            helper.setVisible(R.id.mLinear_pmv,true);
            helper.setText(R.id.mText_pmv,toTime(split[2]));
            helper.setImageResource(R.id.mImage_type,R.mipmap.picture_video);
            Glide.with( mContext )
                    .load( Uri.fromFile( new File( split[1] ) ) )
                    .into( mImage_pmv );
        }
    }
    //转化分以内的时间格式为 00:00
    String toTime(String time){
        String tm = "";
        long l = Long.parseLong(time);
        long l1 = l / 1000;
        if (l1<60) {
            if (l1>=10) {
                tm="00:"+String.valueOf(l1);
            }else{
                tm="00:0"+l1;
            }
        }else{
            long l2 = l1 / 60;
            long l3 = l1 % 60;
            if (l2<10&&l3<10) {
                tm = "0"+l2+":0"+l3;
            } else if (l2<10&&l3>=10) {
                tm = "0"+l2+":"+l3;
            } else if (l2>=10&&l3>=10) {
                tm = l2+":"+l3;
            }else{
                tm = l2+":0"+l3;
            }
        }
        return tm;
    }
}
